use Operation;
use Map;

package CheckCellOccupied;
@ISA=qw/Operation/;

sub init{
    my $self = shift;
    $self->dependencies(qw/LogManager/);
}

sub perform{
    my $self = shift;

    my ($map, $pos) = ($self->params->{MAP}, $self->params->{POS});
    my $cell = $map->tiles->[$pos->[0]][$pos->[1]]; 
    
    my @entities = @{$cell->contents->category("CREATURE")};
    my @constructions = @{$cell->contents->category("CONSTRUCTION")};
    
    my $lm = $self->{LogManager};
    $lm->log(ref($self)." - Checking ".$pos->[0]."; ".$pos->[1]);
    $lm->log(ref($self)." - ".scalar(@entities)." - ".scalar(@constructions));

    if(scalar(@entities) > 0 || scalar(@constructions) > 0){
	return ActionResult->new("CELL_OCCUPIED", "Occupied!");
    }
    return ActionResult->new("SUCCESS", "OK");
}

1;
